package edu.ccut.saturn.workflow.delegate;

import java.sql.Connection;
import java.util.ArrayList;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.SaturnData;
import edu.ccut.saturn.operation.Operation;
import edu.ccut.saturn.workflow.common.Constants;

public class QueryDelegateTask extends DefaultComponent {
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		String userId = (String)parameterContext.getParameterValue(0);
		Connection conn = parameterContext.getConnection();
		
		String sql="select * from wf_delegate where delegate_from='"+userId+"' and state='1'";//运行
		ArrayList<SaturnData> delegateInstList = Operation.dataBase()
				.queryBySQL(Constants.SATURNDATA_WF_DELEGATE, sql, conn);
		ArrayList<SaturnData> workitemInstList = new ArrayList<SaturnData>();
		if(delegateInstList!=null){
			for(SaturnData delegateInst:delegateInstList){
				SaturnData workitemInst = Operation.dataBase().queryByPrimaryKey(Constants.SATURNDATA_WF_WORKITEM_INSTANCE, 
						delegateInst.get("workitem_id")+"", conn);
				if(workitemInst!=null){
					workitemInstList.add(workitemInst);
				}
			}
		}
		parameterContext.setParameter(1, workitemInstList);
	} 
}